import { ApiRes, BannerItem,Brand,GoodItem ,HotGoods,HomeProduct, Special} from '@/types/data'
import request from '@/utils/request'
import {defineStore} from 'pinia'
export  const useBannerStore = defineStore('home',{
  state(){
    return {
      bannerList : [] as BannerItem[],
      newGoodsList:[] as GoodItem[],
      hotList:[] as HotGoods[],
      brandList:[] as Brand[],
      productList:[] as HomeProduct[],
      specialList:[] as Special[]

    }
  },
  actions:{
    async getBannerList(){
      const res = await request.get<ApiRes<BannerItem[]>>('/home/banner')
      this.bannerList = res.data.result
    },
    async getGoodsList(){
      const res = await request.get<ApiRes<GoodItem[]>>('/home/new')
      this.newGoodsList = res.data.result     
    },
    // 人气推荐
    async getHotList(){
      const res = await request.get<ApiRes<HotGoods[]>>('/home/hot')
      this.hotList = res.data.result
      
    },
    // 热门品牌
    async getBrandList() {
      const res = await request.get<ApiRes<Brand[]>>('/home/brand')
      console.log(res)
      this.brandList = res.data.result
    },
    // 区块
    async getProductList() {
      const res = await request.get<ApiRes<HomeProduct[]>>('/home/goods')
      this.productList = res.data.result
    },
    // 指定专区
    async getSpecialList() {
      const res = await request.get<ApiRes<Special[]>>('/home/special')
      this.specialList = res.data.result
    },
  }
})